<template>
  <ui-dropdown
    class="ui-more-dropdown"
    :class="['ui-more-dropdown--' + size, 'is-' + type, { 'is-wisp': wisp, 'is-border': border, 'is-round': round }]"
    @command="handleCommandChange"
  >
    <template slot="reference" slot-scope="{ visible }">
      <div class="ui-more-dropdown__handle" :class="{'is-active': visible}" @click.stop.prevent>
        <span class="ui-more-dropdown__handle-icon" />
      </div>
    </template>
    <slot />
  </ui-dropdown>
</template>
<script>
import { Dropdown } from '../dropdown'

export default {
  name: 'UiMoreDropdown',
  props: {
    type: {
      type: String,
      default: 'dark',
      validator (value) {
        return ['dark', 'light'].includes(value)
      }
    },
    size: {
      type: String,
      default: 'small',
      validator(value) {
        return ['medium', 'small', 'mini'].includes(value)
      }
    },
    border: {
      type: Boolean,
      default: false
    },
    round: {
      type: Boolean,
      default: false
    },
    wisp: {
      type: Boolean,
      default: false
    }
  },
  components: {
    UiDropdown: Dropdown
  },
  methods: {
    handleCommandChange(evt) {
      this.$emit('command', evt)
    }
  }
}
</script>
<style lang="less">
.ui-more-dropdown{
  &.is-wisp {
    .ui-more-dropdown__handle{
      padding-left: 0;
      padding-right: 0;
      &:hover, &.is-active {
        &:after {
          background-color: #333;
        }
        .ui-more-dropdown__handle-icon{
          &:after, &:before{
            background-color: #333;
          }
        }
      }
    }
  }
  &:not(.is-wisp) {
    .ui-more-dropdown__handle{
      &:hover, &.is-active {
        background-color: rgba(0,0,0,.06);
      }
    }
  }
  &.is-border {
    .ui-more-dropdown__handle{
      border: 1px solid #DCDFE6;
    }
  }
  &.is-dark {
    .ui-more-dropdown__handle{
      &:after {
        background-color: #999;
      }
    }
    .ui-more-dropdown__handle-icon{
      &:after, &:before{
        background-color: #999;
      }
    }
  }
  &.is-light {
    .ui-more-dropdown__handle{
      &:after {
        background-color: rgba(255, 255, 255, .7);
      }
    }
    .ui-more-dropdown__handle-icon{
      &:after, &:before{
        background-color: rgba(255, 255, 255, .7);
      }
    }
  }
}
.ui-more-dropdown__handle{
  height: 3px;
  border-radius: 3px;
  cursor: pointer;
  transition: all .25s;
  box-sizing: border-box;
  display: flex;
  flex-direction: row;
  justify-content: center;
  align-items: center;
  &:after {
    content: '';
    display: inline-block;
    vertical-align: top;
    width: 3px;
    height: 3px;
    border-radius: 50%;
    margin: -1px 1px 0;
  }
}
.ui-more-dropdown__handle-icon{
  position: relative;
  height: 3px;
  display: inline-block;
  line-height: 0;
  vertical-align: top;
  margin-top: -1px;
  &:after, &:before{
    content: '';
    display: inline-block;
    vertical-align: top;
    width: 3px;
    height: 3px;
    border-radius: 50%;
    margin: 0 1px;
  }
}
.ui-more-dropdown--medium {
  .ui-more-dropdown__handle{
    padding-left: 12px;
    padding-right: 12px;
    height: 36px;
    line-height: 36px;
  }
}
.ui-more-dropdown--small {
  .ui-more-dropdown__handle{
    padding-left: 9px;
    padding-right: 9px;
    height: 32px;
    line-height: 32px;
  }
}
.ui-more-dropdown--mini {
  .ui-more-dropdown__handle{
    height: 24px;
    padding-left: 5px;
    padding-right: 5px;
  }
  &.is-round {
    .ui-more-dropdown__handle{
      border-radius: 50%;
    }
  }
}
</style>
